package fourFragment.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;

import common.BaseActivity;
import common.BaseFragmentAdapter;
import fourFragment.fragment.MyFocusCollege;
import fourFragment.fragment.MyFocusTopic;
import fourFragment.fragment.MyFocusVolunteer;
import view.MyPagerSlidingTabStrip;
import view.MyViewPager;

/**
 * Created by Administrator on 2017/4/7.
 * 我的关注
 */
@ContentView(R.layout.myattention)
public class MyAttention extends BaseActivity implements View.OnClickListener {
    @ViewInject(R.id.myAttention_tabStrip)
    private MyPagerSlidingTabStrip myAttention_tabStrip;
    @ViewInject(R.id.myAttention_viewPager)
    private MyViewPager myAttention_viewPager;
    @ViewInject(R.id.common_back)
    private ImageView back;
    @ViewInject(R.id.common_title)
    private TextView title;

    private MyFocusCollege myFocusCollege1;
    private MyFocusVolunteer myFocusCollege2;
    private MyFocusTopic myFocusCollege3;

    private android.support.v4.app.FragmentManager fragmentManager;
    private BaseFragmentAdapter baseFragmentAdapter;
    private ArrayList<Fragment> fragments;
    private int tabs_color, tabs_text_size, tabs_color_chosed;
    private String[] tabs = new String[]{"院校", "志愿者", "话题"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initTabStrip();


    }

    private void initView() {
        title.setText("我的关注");
        back.setOnClickListener(this);
    }

    private void initTabStrip() {
        myFocusCollege1 = new MyFocusCollege();
        myFocusCollege2 = new MyFocusVolunteer();
        myFocusCollege3 = new MyFocusTopic();

        fragments = new ArrayList<>();
        fragments.add(myFocusCollege1);
        fragments.add(myFocusCollege2);
        fragments.add(myFocusCollege3);
        tabs_color_chosed = this.getResources().getColor(R.color.common_color);
        tabs_color = this.getResources().getColor(R.color.tab_color);
        tabs_text_size = this.getResources().getDimensionPixelSize(R.dimen.text_size);
        fragmentManager = this.getSupportFragmentManager();
        baseFragmentAdapter = new BaseFragmentAdapter(fragmentManager, fragments, tabs);

        myAttention_viewPager.setAdapter(baseFragmentAdapter);
        myAttention_viewPager.setOffscreenPageLimit(3);
        myAttention_tabStrip.setTextColor(tabs_color);
        myAttention_tabStrip.setTextSize(tabs_text_size);
        myAttention_tabStrip.setDividerColor(Color.TRANSPARENT);
        myAttention_tabStrip.setDividerPadding(1);
        myAttention_tabStrip.setUnderlineHeight(0);
        myAttention_tabStrip.setIndicatorColor(tabs_color_chosed);
        myAttention_tabStrip.setIndicatorHeight(4);
        myAttention_tabStrip.setTabPaddingLeftRight(32);
        myAttention_tabStrip.setIndicatorPadding(30, 30);
        myAttention_tabStrip.setSelectedTextColor(tabs_color_chosed);
        myAttention_tabStrip.setViewPager(myAttention_viewPager, null);
        myAttention_tabStrip.setShouldExpand(true, null);
        myAttention_tabStrip.setOnPageChangeListener(
                new ViewPager.OnPageChangeListener() {
                    @Override
                    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                    }

                    @Override
                    public void onPageSelected(final int position) {

                    }

                    @Override
                    public void onPageScrollStateChanged(int state) {
                    }
                }

        );
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.common_back:
                this.finish();
                break;
            default:
                break;
        }
    }
}
